import json

import requests
import yaml


class BaseApi:
    env = yaml.safe_load(open('env.yaml'))

    # def send(self, data: dict):
    #     return requests.request(**data)
    def send(self, data: dict):
        # data['url'] = json.dumps(data['url']).replace('testing-studio', '127.0.0.1')
        data['url'] = str(data['url']).replace('testing-studio', self.env['testing-studio'][self.env['default']])
        print(data['url'])
        return requests.request(method=data['method'], url=data['url'], headers=data['headers'])

    def session_send(self, data: dict):
        session = requests.Session()
        if data['method'] == 'get':
            return session.get(url=data['url'], params=data['params'])
        else:
            return session.post(url=data['url'], json=data['json'])


if __name__ == '__main__':
    data = {
        "method": "get",
        "url": 'http://testing-studio:9999/demo1.txt',
        "headers": None
    }
    print(BaseApi().send(data))
